<template>
	<view>
		<view class="head">
			<view class="head_left" @tap="back()">
				<image src="../../../static/wode/return.png" mode=""></image>
				<text>教学中心</text>
			</view>
			<view class="head_mid">
				消息中心
			</view>
			<view class="head_right">

			</view>
		</view>
		<view class="padding-box">
			<!-- <view class="messageBox">
				<view class="time">20:10</view>
				<view class="message_item">
					<view class="message_left">
						<image src="../../../static/avatar.jpg" mode=""></image>
						<view class="message_body">
							<view class="">
								<text class="text1">用户名</text>
								<text class="text2">申请取消预约</text>
							</view>
							<text>《主题》 09:00~09:30</text>
						</view>
					</view>
					<view class="message_right">
						<view class="agree">
							同意
						</view>
						<view class="refuse">
							拒绝
						</view>
					</view>

				</view>
			</view> -->
			<view class="" v-for="(item,index) in dataList" :key="index">
				<view class="messageBox" v-if="item.type=='curriculumcancel'">
					<view class="time">{{item.create_time}}</view>
					<view class="message_item">
						<view class="message_left">
							<image :src="item.map.userinfo.avatar" mode=""></image>
							<view class="message_body">
								<view class="">
									<text class="text1" v-if="item.identity=='user'">{{item.map.userinfo.nick_name}}</text>
									<text class="text1" v-else-if="item.identity=='master'">{{item.map.masterinfo.info.nick_name}}</text>
									<text class="text2">申请取消预约</text>
								</view>
								<text>《{{item.map.userAppointmentInfo.title}}》 {{item.timeNum}}</text>
							</view>
						</view>
						<view class="message_right" v-if="item.status==1&&item.identity!=type">
							<view class="agree" @tap="setConfirm('agree',item,index)">
								同意
							</view>
							<view class="refuse" @tap="setConfirm('refuse',item,index)">
								拒绝
							</view>
						</view>
						<view class="message_right" v-else-if="item.status==1&&item.identity==type">
							<text>等待对方处理</text>
						</view>
						<view class="message_right" v-else-if="item.status==2">
							<text v-if="item.handle==1" class="text3">已同意</text>
							<text v-else-if="item.handle==2" class="text3">已拒绝</text>
						</view>

					</view>
				</view>
				<view class="messageBox" v-else-if="item.type=='curriculumupdate'">
					<view class="time">{{item.create_time}}</view>
					<view class="message_item">
						<view class="message_left">
							<image :src="item.map.userinfo.avatar" mode=""></image>
							<view class="message_body">
								<view class="">
									<text class="text1">{{item.map.userinfo.nick_name}}</text>
									<text class="text2">申请修改预约</text>
								</view>
								<text>《{{item.map.userAppointmentInfo.title}}》 {{item.timeNum}}</text>
							</view>
						</view>
						<view class="message_right" v-if="item.status==1&&item.identity!=type">
							<view class="agree" @tap="setConfirm('agree',item,index)">
								同意
							</view>
							<view class="refuse" @tap="setConfirm('refuse',item,index)">
								拒绝
							</view>
						</view>
						<view class="message_right" v-else-if="item.status==1&&item.identity==type">
							<text>等待对方处理</text>
						</view>
						<view class="message_right" v-else-if="item.status==2">
							<text v-if="item.handle==1" class="text3">已同意</text>
							<text v-else-if="item.handle==2" class="text3">已拒绝</text>
						</view>
					</view>
					<view class="changeBox">
						<text>改为</text>《{{item.map.userAppointmentInfo.title}}》 {{item.update_timeNum}}
					</view>
				</view>
				<view class="messageBox" v-else-if="item.type=='curriculumappointment'">
					<view class="time">{{item.create_time}}</view>
					<view class="message_item">
						<view class="message_left">
							<image :src="item.map.userinfo.avatar" mode=""></image>
							<view class="message_body">
								<view class="">
									<text class="text1">{{item.map.userinfo.nick_name}}</text>
								</view>
								<text>《{{item.map.userAppointmentInfo.title}}》 {{item.timeNum}}</text>
							</view>
						</view>
						<text class="text2">预约成功</text>
					</view>
				</view>
			</view>

			<!-- <view class="messageBox">
				<view class="time">20:10</view>
				<view class="message_item">
					<view class="message_left">
						<image src="../../../static/avatar.jpg" mode=""></image>
						<view class="message_body">
							<view class="">
								<text class="text1">用户名</text>
							</view>
							<text>《主题》 09:00~09:30</text>
						</view>
					</view>
					<text class="text2">预约成功</text>
				</view>
			</view>
			<view class="messageBox">
				<view class="time">20:10</view>
				<view class="message_item">
					<view class="message_left">
						<image src="../../../static/avatar.jpg" mode=""></image>
						<view class="message_body">
							<view class="">
								<text class="text1">用户名</text>
							</view>
							<text>《主题》 09:00~09:30</text>
						</view>
					</view>
					<text class="text2">修改成功</text>

				</view>
				<view class="changeBox">
					<text>改为</text>《另一主题》 10:00~10:30
				</view>
			</view> -->
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: '',
				dataList: ''
			}
		},
		onLoad(option) {
			this.type = option.type
		},
		onShow() {
			this.getData()
			this.setRead()
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			setRead() {
				var me = this
				if (this.type == 'master') {
					var data = {
						master_id: uni.getStorageSync('user_id')
					}
				} else if (this.type == 'user') {
					var data = {
						user_id: uni.getStorageSync('user_id')
					}
				}
				this.myAjaxNewPost({
					model: 'user',
					controllerName: "masterNotice",
					actionName: 'updateIsRead',
					data: data,
					successBack: function(res) {
						console.log(res)
					},
				})
			},
			getData() {
				var me = this
				if (this.type == 'master') {
					var data = {
						master_id: uni.getStorageSync('user_id')
					}
				} else if (this.type == 'user') {
					var data = {
						user_id: uni.getStorageSync('user_id')
					}
				}
				this.myAjaxNew({
					model: 'user',
					controllerName: "masterNotice",
					actionName: 'queryListPage',
					data: data,
					successBack: function(res) {
						console.log(res, '消息')
						me.dataList = res.data.data
						if (me.dataList.length != 0) {
							for (var i = 0; i < me.dataList.length; i++) {
								me.dataList[i].map.userAppointmentInfo.start_time = me.dataList[i].map.userAppointmentInfo.start_time.split(
									' ')
								me.dataList[i].map.userAppointmentInfo.end_time = me.dataList[i].map.userAppointmentInfo.end_time.split(' ')
								me.dataList[i].dayNum = me.dataList[i].map.userAppointmentInfo.start_time[0].substr(me.dataList[i].map.userAppointmentInfo
									.start_time[0].length - 2, 2)
								me.dataList[i].timeNum = me.dataList[i].map.userAppointmentInfo.start_time[1].substr(0, 5) + '~' + me.dataList[
									i].map.userAppointmentInfo.end_time[1].substr(0, 5)
								if (me.dataList[i].type == "curriculumupdate") {
									me.dataList[i].map.updateAppointmentEntity.start_time = me.dataList[i].map.updateAppointmentEntity.start_time
										.split(' ')
									me.dataList[i].map.updateAppointmentEntity.end_time = me.dataList[i].map.updateAppointmentEntity.end_time.split(
										' ')
									me.dataList[i].update_timeNum = me.dataList[i].map.updateAppointmentEntity.start_time[1].substr(0, 5) + '~' +
										me.dataList[i].map.updateAppointmentEntity.end_time[1].substr(0, 5)
								}
							}
						}

					}
				})

			},
			setConfirm(confirm, item, index) { //
				var me = this;
				var data = {
					update_identity: item.identity,
					masterNotice_id: item.id,
					master_type: item.map.userAppointmentInfo.master_type,
					master_id: item.map.userAppointmentInfo.master_id,
					user_id: item.user_id,
					master_id: item.master_id,
					id: item.map.userAppointmentInfo.id,
					update_type: item.type,
					appointment_id: item.map.userAppointmentInfo.appointment_id
				}
				if (confirm == 'agree') {
					data.whether = true
				} else if (confirm == 'refuse') {
					data.whether = false
				}
				if (item.type == "curriculumupdate") {
					data.update_appointment_id = item.map.updateAppointmentEntity.id
				}
				this.myAjaxNewPost({
					model: 'user',
					controllerName: "userAppointment",
					actionName: 'updateConfirm',
					data: data,
					successBack: function(res) {
						console.log(res)
						if (res.data.message == '成功') {
							var obj = me.dataList[index]
							obj.status = 2
							if (confirm == 'agree') {
								obj.handle = 1
							} else if (confirm == 'refuse') {
								obj.handle = 2
							}
							me.dataList.splice(index, 1, obj) //页面显示处理
						}
					}
				})
			}
		}
	}
</script>

<style scoped>
	.head {
		width: 100%;
		display: flex;
		justify-content: space-between;
		height: 128upx;
		background: #ffffff;
		padding: 0 24upx;
		z-index: 200;
		position: fixed;
		top: 0;
	}

	.head image {
		width: 20upx;
		height: 36upx;
		margin-right: 9upx;
	}

	.head_left {
		height: 82upx;
		display: flex;
		align-items: center;
		line-height: 82upx;
		color: #666666;
		font-size: 32upx;

	}

	.head_right {
		width: 156upx;
	}

	.padding-box {
		padding-top: 128upx;
	}

	.time {
		width: 100%;
		text-align: center;
		font-size: 24upx;
		color: #CCCCCC;
		margin: 40upx 0 20upx 0;
	}

	.message_item {
		background: #FFFFFF;
		padding: 0 24upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 180upx;
		border-bottom: 1upx solid #E6E6E6;
	}

	.message_left {
		display: flex;
		align-items: center;
	}

	.message_left image {
		width: 106upx;
		height: 106upx;
		border-radius: 50%;
		overflow: hidden;
		margin-right: 20upx;
	}

	.message_body {
		display: flex;
		flex-direction: column;
		color: #666666;
		font-size: 26upx;
		justify-content: space-between;
		height: 110upx;
	}

	.text1 {
		color: #333333;
		font-size: 32upx;
		margin-left: 10upx;
		margin-right: 30upx;
		font-weight: bold;
	}

	.text2 {
		color: #46CECF;
		font-size: 28upx;
		font-weight: bold;

	}

	.message_right {
		display: flex;
		flex-direction: column;
	}

	.agree,
	.refuse {
		width: 110upx;
		height: 60upx;
		border-radius: 10upx;
		color: #FFFFFF;
		font-size: 28upx;
		text-align: center;
		line-height: 60upx;
	}

	.agree {
		background: #46CECF;
		margin-bottom: 20upx;
	}

	.refuse {
		background: #E6E6E6;
	}

	.text3 {
		color: #999999;
		font-size: 28upx;
	}

	.changeBox {
		background: #FFFFFF;
		text-align: center;
		height: 78upx;
		line-height: 78upx;
		color: #333333;
		font-size: 26upx;
	}

	.changeBox text {
		color: #999999;
	}
</style>
